package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TicketSellDetail;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.TicketSellDetailMapper;
import cn.wolfcode.trip.base.mapper.UserMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ITicketDetailService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TicketDetailServiceImpl implements ITicketDetailService {
    @Autowired
    private TicketSellDetailMapper ticketSellDetailMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public void save(Long userId,TicketSellDetail entity) {
        User user = userMapper.selectByPrimaryKey(userId);
        //设置购买时期
        Date date=new Date();
        entity.setBuyingdate(date);
        entity.setUser(user);
        ticketSellDetailMapper.insert(entity);
    }

    @Override
    public PageInfo<TicketSellDetail> queryTicketDetailsByUserId(Long userId,QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<TicketSellDetail> list= ticketSellDetailMapper.selectTicketDetailsByUserId(userId,qo);
        return new PageInfo<TicketSellDetail>(list);
    }
}
